// pages/specia/specia.js
Page({
  onShareAppMessage() {
    return {
      title: 'checkbox',
      path: 'page/component/pages/checkbox/checkbox'
    }
  },
  /**
   * 页面的初始数据
   */
  data: {
    deskId:'',
    deskCaption:'',
    items: [],
    //备注
    text1:'',
    values1:'',
    text2:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      deskId:options.deskId,
      deskCaption:options.deskCaption
    })
    this.getSpecia()
  },
   //返回上一页
   toback() {
    wx.navigateBack({
      delta: 1
    })
  },
  //获取口味列表
  getSpecia(){
    wx.request({
      url: 'http://www.szyzit.com:8080/CateringSystem1.0/recruitment/catering/postOrderMenu.do?method=login',
      method:'POST',
      header:{'Content-type': 'application/x-www-form-urlencoded'},
      data:{
        deskId:this.data.deskId,
        status:0,
      },
      success:(res)=>{
        console.log('请求成功')
      },
      fail:(res)=>{
        wx.showToast({
          title: '请求失败',
        })
      }
    })
    wx.request({
      url: 'http://www.szyzit.com:8080/CateringSystem1.0/recruitment/catering/qryMenuItemSpecialRequest.do?method=login',
      method:'POST',
      header:{'Content-type': 'application/x-www-form-urlencoded'},
      success:(res)=>{
        this.setData({
          items:res.data.responseBody.menuItemSpecialRequest
        })
      },
      fail:(res)=>{
        wx.showToast({
          title: '请求失败',
        })
      }
    })
  },
  //勾选更新data
  checkboxChange(e) {
    console.log('checkbox发生change事件，携带value值为：', e.detail.value)

    const items = this.data.items
    const values = e.detail.value
    for (let i = 0, lenI = items.length; i < lenI; ++i) {
      items[i].checked = false

      for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
        if (items[i].value === values[j]) {
          items[i].checked = true
          break
        }
      }
    }

    this.setData({
      items,
      values1:e.detail.value
    })
  },
  //备注
  bindTextAreaBlur(e) {
    this.setData({
      text1:e.detail.value
    })
    // console.log(e.detail.value)
  },
  login(){
    const values2=`${this.data.values1.join()},${this.data.text1}`
    // console.log('备注1',values2)
    // console.log('备注2',this.data.text1)
   wx.navigateTo({
     url: '/pages/myMenu/myMenu?deskId='+this.data.deskId+'&deskCaption='+this.data.deskCaption+'&values='+values2,
   })
  }
})